﻿var app = angular.module('app', ['angular.jquery']);
var item = null;
var flag = false;
var url = Editor.Url;
var pageId = 2;
var pageSize = 10;
var nvId = 2;

app.controller('DemoCtrl', [
    '$scope', '$http',
    'AppDialogService',
function ($scope, $http, AppDialogService) {
    'use strict';    
    $http.get(url + "/nv/GetAll")
     .success(function (response) {
     });
    var nvitem = Editor.read("detail");
    if (nvitem != null) {
        nvId = nvitem.iD;
    }
    var params = {
        "id": nvId,        
    };

    $http.post(url + "/nv/GetInfo", params).success(function (response) {        
        $scope.nhanviens = response;
    });

    $http.post(url + "/nv/GetThanNhan", params).success(function (response) {        
        $scope.thannhans = response;
        if (response.length == 0) {
            $("#thannhan").hide();
        }
        else {
            $("#thannhan").show();
        }
    });

    $http.post(url + "/nv/GetGiaoLy", params).success(function (response) {        
        $scope.giaolys = response;
        if (response.length == 0) {
            $("#giaoly").hide();
        }
        else {
            $("#giaoly").show();
        }
    });


    $http.get(url + "/TD/GetAll")
    .success(function (response) {
        $scope.trinhdos = response;
    });
    $http.get(url + "/vu/GetVuDetails")
    .success(function (response) {
        $scope.vus = response;
    });

    $scope.loadData = function () {
        $http.get(url + "/nv/GetAll")
                .success(function (response) {
                    $scope.nhanviens = response;
                });
    }

    $scope.delete = function (id) {
        var a = confirm("Bạn có thực sự muốn xóa dòng này?");
        if (a === false)
            return;
        $http.delete(url + "/api/NhanVienAPI/" + id).success(function (data, status, headers) {
            $scope.loadData();
        });
    }
    
    $scope.appDialog = function (_flag, _item) {
        item = _item;
        flag = _flag;
        AppDialogService.openDialog({
            testValue: 'application'
        }).then(function (result) {
            if (result.ok) {
               
            }
        });

    };

}]);

app.controller('DialogCtrl', [
    '$scope',
    'AppDialogService',
function ($scope, AppDialogService) {
    'use strict';

    $scope.nv = null;

    $scope.onOpen = function () {
      
    };

    $scope.$parent.onOk = function () {
        
        AppDialogService.closeDialog({ ok: true, obj: $scope.nv });
    };

    $scope.onCancel = function () {
        AppDialogService.closeDialog({ ok: false });
    };

    $scope.beforeClose = function () {
        return "";
    };

}]);